package dodizhu;

import com.sun.source.tree.Tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

/**
 * Date: 2023-04-24
 * Time: 17:05
 */
public class pokerGame {

    // 准备牌盒
    static ArrayList<Integer> list = new ArrayList<>();
    static HashMap<Integer,String> hm = new HashMap<>();

    static{
        String[] color = {"♥","♠","♣","♦"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        int serialNumber = 1;


        // 先遍历数字,在遍历花色,可保证有序
        for(String n:number){
            for(String c:color){
                hm.put(serialNumber,c+n);
                list.add(serialNumber);
                serialNumber++;
            }
        }
        hm.put(serialNumber,"小王");
        list.add(serialNumber);
        serialNumber++;
        hm.put(serialNumber,"大王");
        list.add(serialNumber);
    }

    public pokerGame(){
        // 洗牌,实际上洗的是序号
        Collections.shuffle(list);

        // 发牌
        TreeSet<Integer> lord = new TreeSet<>();
        TreeSet<Integer> poker1 = new TreeSet<>();
        TreeSet<Integer> poker2  = new TreeSet<>();
        TreeSet<Integer> poker3 = new TreeSet<>();

        for (int i = 0; i < list.size(); i++) {
            if(i<3){
                // 添加底牌
                lord.add(list.get(i));
                continue;
            }
            if(i%3==0){
                poker1.add(list.get(i));
            } else if (i%3==1) {
                poker2.add(list.get(i));
            }else{
                poker3.add(list.get(i));
            }
        }

        // 看牌
        lookPoker("底牌",lord);
        lookPoker("刚脑壳",poker1);
        lookPoker("大帅比",poker2);
        lookPoker("饭桶",poker3);

    }

    public void lookPoker(String name, TreeSet<Integer> ts){
        System.out.print(name+" ");
        // 键找值
        // 遍历集合拿到序号,根据序号到tm集合中找到相应的值
        for(int serialNumber:ts){
            String poker = hm.get(serialNumber);
            System.out.print(poker+" ");
        }
        System.out.println();
    }
}
